<template>
  <div class="home-container">
    <div class="banner">
      <el-carousel height="400px" indicator-position="outside" :interval="5000">
        <el-carousel-item v-for="(item, index) in bannerList" :key="index">
          <div class="banner-item" :style="{ backgroundImage: `url(${item.imageUrl})` }">
            <div class="banner-content">
              <h2>{{ item.title }}</h2>
              <p>{{ item.description }}</p>
              <el-button type="primary" v-if="item.buttonText" @click="handleBannerClick(item)">
                {{ item.buttonText }}
              </el-button>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>

    <div class="section museum-intro">
      <div class="section-header">
        <h2>博物馆介绍</h2>
        <div class="divider"></div>
        <p class="subtitle">传承文明 • 守护历史 • 启迪未来</p>
      </div>
      <div class="intro-content">
        <div class="intro-text">
          <p>{{ museumIntro.description }}</p>
          <div class="intro-stats">
            <div class="stat-item">
              <h3>100,000+</h3>
              <p>馆藏文物</p>
            </div>
            <div class="stat-item">
              <h3>20+</h3>
              <p>常设展览</p>
            </div>
            <div class="stat-item">
              <h3>2,000,000+</h3>
              <p>年访问量</p>
            </div>
          </div>
          <el-button type="primary" class="learn-more-btn" @click="goToMuseumInfo">
            <el-icon class="mr-5"><ArrowRight /></el-icon>
            了解更多
          </el-button>
        </div>
        <div class="intro-image-wrapper">
          <img src="@/assets/images/people.jpg" alt="博物馆展厅" class="intro-image">
          <div class="image-caption">
            <el-icon><Picture /></el-icon>
            <span>现代化展厅环境，为观众提供沉浸式文化体验</span>
          </div>
        </div>
      </div>
    </div>

    <div class="section featured-exhibits">
      <div class="section-header">
        <h2>精选藏品</h2>
        <div class="divider"></div>
        <p class="subtitle">穿越时空，感受文明的魅力</p>
      </div>
      <el-row :gutter="30" class="exhibit-list">
        <el-col :xs="24" :sm="12" :md="6" v-for="(exhibit, index) in featuredExhibits" :key="index">
          <div class="exhibit-card" @click="goToExhibitDetail(exhibit)">
            <div class="exhibit-image">
              <img :src="exhibit.imageUrl" :alt="exhibit.name">
              <div class="exhibit-overlay">
                <el-icon><ZoomIn /></el-icon>
              </div>
            </div>
            <div class="exhibit-info">
              <h3>{{ exhibit.name }}</h3>
              <p class="exhibit-location">{{ exhibit.location }}</p>
              <p class="exhibit-desc">{{ exhibit.description }}</p>
            </div>
          </div>
        </el-col>
      </el-row>
      <div class="view-more">
        <el-button type="primary" class="view-more-btn" @click="goToExhibits">
          浏览更多藏品
          <el-icon class="ml-5"><ArrowRight /></el-icon>
        </el-button>
      </div>
    </div>

    <div class="section visit-info">
      <div class="section-header">
        <h2>参观指南</h2>
        <div class="divider"></div>
        <p class="subtitle">便捷贴心的参观服务</p>
      </div>
      <el-row :gutter="30" class="info-cards">
        <el-col :xs="24" :sm="12" :md="8">
          <div class="info-card">
            <div class="card-icon">
              <el-icon><Clock /></el-icon>
            </div>
            <div class="card-content">
              <h3>开放时间</h3>
              <ul>
                <li>周二至周日: 9:00 - 17:00</li>
                <li>周一闭馆（法定节假日除外）</li>
                <li>16:30停止入场</li>
              </ul>
            </div>
          </div>
        </el-col>
        <el-col :xs="24" :sm="12" :md="8">
          <div class="info-card">
            <div class="card-icon">
              <el-icon><Ticket /></el-icon>
            </div>
            <div class="card-content">
              <h3>门票信息</h3>
              <ul>
                <li>成人票: ¥60/人</li>
                <li>学生票: ¥30/人（凭学生证）</li>
                <li>老人票: ¥30/人（65岁以上）</li>
                <li>儿童: 1.2米以下免费</li>
              </ul>
            </div>
          </div>
        </el-col>
        <el-col :xs="24" :sm="12" :md="8">
          <div class="info-card">
            <div class="card-icon">
              <el-icon><Location /></el-icon>
            </div>
            <div class="card-content">
              <h3>交通指南</h3>
              <ul>
                <li>地址: 博物馆路100号</li>
                <li>公交: 1路, 15路, 22路</li>
                <li>地铁: 1号线博物馆站</li>
                <li>停车: 博物馆地下停车场</li>
              </ul>
            </div>
          </div>
        </el-col>
      </el-row>
      <div class="appointment-btn">
        <el-button type="primary" size="large" class="make-appointment-btn" @click="goToAppointment">
          <el-icon><Calendar /></el-icon>
          立即预约参观
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref, onMounted} from 'vue'
import {useRouter} from 'vue-router'
import {Clock, Ticket, Location, Calendar, ArrowRight, ZoomIn, Picture} from '@element-plus/icons-vue'
import {getFeaturedCollections} from '@/api/collections'

const router = useRouter()

// 模拟数据，实际应从API获取
const bannerList = ref([
  {
    imageUrl: '/src/assets/images/banner1.jpg',
    title: '穿越时空的文明印记',
    description: '探索千年文明，感受历史的厚重与传承',
    buttonText: '预约参观',
    link: '/visitor/appointment'
  },
  {
    imageUrl: '/src/assets/images/banner2.jpg',
    title: '国宝新展：玉器与青铜器特展',
    description: '商周时期珍贵文物，展现古代工艺的卓越成就',
    buttonText: '展览详情',
    link: '/visitor/collections'
  },
  {
    imageUrl: '/src/assets/images/banner3.jpg',
    title: '丝路文化展：东西方文明的交融',
    description: '探寻丝绸之路上的文化交流与艺术传承',
    buttonText: '在线导览',
    link: '/visitor/map'
  },
  {
    imageUrl: '/src/assets/images/banner4.jpg',
    title: '数字化展厅全新开放',
    description: '运用现代科技，带来沉浸式的观展体验',
    buttonText: '了解更多',
    link: '/visitor/museum-info'
  }
])

const museumIntro = ref({
  description: '博物馆创建于1950年，是国家一级博物馆，馆藏文物超过10万件，包括陶瓷、青铜、玉器、书画等多个门类。博物馆建筑面积5万平方米，常设展览20个，每年接待观众超过200万人次。博物馆致力于文物保护、研究和展示，为公众提供优质的文化服务。'
})

// 精选藏品数据
const featuredExhibits = ref([])

// 获取精选藏品数据
const loadFeaturedExhibits = async () => {
  try {
    const res = await getFeaturedCollections({limit: 4})
      featuredExhibits.value = res
  } catch (error) {
    console.error('获取精选藏品失败:', error)
  }
}

// 页面加载时获取数据
onMounted(() => {
  loadFeaturedExhibits()
})

// 页面跳转方法
const handleBannerClick = (item) => {
  router.push(item.link)
}

const goToMuseumInfo = () => {
  router.push('/visitor/museum-info')
}

const goToExhibits = () => {
  router.push('/visitor/collections')
}

const goToAppointment = () => {
  router.push('/visitor/appointment')
}

const goToExhibitDetail = (exhibit) => {
  router.push({
    path: '/visitor/collections',
    query: {id: exhibit.id}
  })
}
</script>

<style scoped>
.home-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
}

.banner {
  margin-bottom: 40px;
}

.banner-item {
  height: 100%;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  position: relative;
}

.banner-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
}

.banner-content {
  position: relative;
  z-index: 1;
  color: #fff;
  padding: 0 50px;
  max-width: 600px;
}

.banner-content h2 {
  font-size: 36px;
  margin-bottom: 16px;
  font-weight: 600;
}

.banner-content p {
  font-size: 18px;
  margin-bottom: 24px;
  line-height: 1.5;
}

.section {
  margin: 80px 0;
  padding: 0;
}

.section-header {
  text-align: center;
  margin-bottom: 48px;
}

.section-header h2 {
  font-size: 36px;
  color: #2c3e50;
  margin-bottom: 16px;
  font-weight: 600;
}

.section-header .subtitle {
  color: #666;
  font-size: 18px;
  margin-top: 16px;
}

.divider {
  width: 60px;
  height: 4px;
  background: linear-gradient(90deg, #409EFF, #67C23A);
  margin: 0 auto;
  border-radius: 2px;
}

.intro-content {
  display: flex;
  gap: 60px;
  align-items: flex-start;
  background: #f8f9fa;
  border-radius: 16px;
  padding: 48px;
}

.intro-text {
  flex: 1;
}

.intro-text p {
  font-size: 16px;
  line-height: 1.8;
  color: #4a4a4a;
  margin-bottom: 32px;
}

.intro-stats {
  display: flex;
  gap: 32px;
  margin-bottom: 32px;
}

.stat-item {
  text-align: center;
}

.stat-item h3 {
  font-size: 28px;
  color: #409EFF;
  margin-bottom: 8px;
}

.stat-item p {
  color: #666;
  margin: 0;
}

.intro-image-wrapper {
  flex: 1;
  position: relative;
}

.intro-image {
  width: 100%;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.image-caption {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.9);
  padding: 12px 24px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.image-caption .el-icon {
  color: #409EFF;
}

.image-caption span {
  color: #606266;
  font-size: 14px;
}

.exhibit-list {
  margin-bottom: 30px;
}

.exhibit-card {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.3s;
  cursor: pointer;
  height: 100%;
}

.exhibit-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.exhibit-image {
  position: relative;
  height: 240px;
  overflow: hidden;
}

.exhibit-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.6s;
}

.exhibit-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}

.exhibit-overlay .el-icon {
  font-size: 32px;
  color: #fff;
}

.exhibit-card:hover .exhibit-overlay {
  opacity: 1;
}

.exhibit-info {
  padding: 20px;
}

.exhibit-info h3 {
  font-size: 18px;
  color: #2c3e50;
  margin-bottom: 8px;
}

.exhibit-location {
  color: #409EFF;
  font-size: 14px;
  margin-bottom: 8px;
}

.exhibit-desc {
  color: #666;
  font-size: 14px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.view-more {
  text-align: center;
  margin-top: 20px;
}

.info-cards {
  margin-bottom: 30px;
}

.info-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  height: 100%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.3s;
}

.info-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.card-icon {
  font-size: 36px;
  color: #409EFF;
  margin-bottom: 24px;
}

.card-content h3 {
  font-size: 20px;
  color: #2c3e50;
  margin-bottom: 16px;
}

.card-content ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.card-content li {
  color: #666;
  margin-bottom: 8px;
  font-size: 15px;
}

.appointment-btn {
  text-align: center;
  margin-top: 30px;
}

.make-appointment-btn {
  font-size: 18px;
  padding: 16px 32px;
  margin-top: 48px;
}

.make-appointment-btn .el-icon {
  margin-right: 8px;
}

@media (max-width: 768px) {
  .intro-content {
    flex-direction: column;
    padding: 24px;
  }

  .intro-stats {
    flex-wrap: wrap;
    gap: 16px;
  }

  .section-header h2 {
    font-size: 28px;
  }

  .section {
    margin: 40px 0;
  }

  .image-caption {
    position: relative;
    bottom: 0;
    transform: none;
    left: 0;
    margin-top: 16px;
    justify-content: center;
  }
}
</style> 